var ChangeManaged = function() {
	return {
		/**
		 * 初始状态
		 */
		init : function() {
			$("#registerTime").datetimepicker({lang:'ch',timepicker:false, format:"Y-m-d"});
			$("#registerTime").val(getStringDate($("#registerTime").val()));
			var path = fileCtx + $("#licensePic").val();
			$("#licensePicImg").attr("src",path);
			this.initTree();
			this.initListener();
		},
		initTree:function() {
			$.ajax({
				"dataType" : 'json',
				"cache" : false,
				"type" : "POST",
				"data" : {},
				"url" : ctx + '/company/getAreaTree?now='+new Date().getTime(),
				"success" : function(data, textStatus, jqXHR) {
					var zNodes = [];
					zNodes = data.data;
					$.fn.zTree.init($("#tree_1"), setting, zNodes);
					var officeAreaIds = $("#officeAreaIds").val();
					var ids = officeAreaIds.split(',');
					var zTree = $.fn.zTree.getZTreeObj("tree_1");
					zTree.checkAllNodes(false);
					zTree.expandAll(true);
					for (var i=0; i < ids.length; i++) {
						if (null != ids[i] && '' != ids[i]) {
							setCheckNodeById(ids[i]);
						}
					}
				}
			});
		},
		/**
		 * 监听开关事件
		 */
		initListener : function() {
			$("#editOfficeInfo").click(function(){
				var postData = $("form[name='addForm']").serializeJson();
				$.ajax({
					"dataType" : 'json',
					"cache": false,
					"type" : "POST",
					"data" : postData,
					"url" : ctx + "/user/doChangeOfficeInfo",
					"success" : function(data) {
						if(data.type=='success'){
							BootstrapDialog.show({
								title : messages.public_cue_cue,
								message : messages.public_cue_saveOk,
								buttons : [ {
									label : messages.public_cue_sure,
									cssClass : 'btn btn-sm btn-primary',
									action : function(dialogItself) {
										dialogItself.close();
										window.location.href = ctx+"/index.html";
									}
								} ]
							});
							
						}else{
							BootstrapDialog.show({
								type : BootstrapDialog.TYPE_WARNING,
								title : messages.public_cue_warning,
								message : data.message,
								buttons : [ {
									label : messages.public_cue_sure,
									cssClass : 'btn btn-sm btn-primary',
									action : function(dialogItself) {
										dialogItself.close();
									}
								} ]
							});
						}
					}
				});
			});
		},
		
		//上传执照图片
        uploadImg : function(){
			$.ajaxFileUpload({
				fileElementId : 'file',// 文件选择框的id属性
				dataType : 'json',// 服务器返回的格式，可以是json
				data : {"dir" : "image"},
				url : ctx + '/upload/file',// 需要链接到服务器地址
				success : function(data, status) {
					if (data['success'] == 1) {
						$("#licensePic").val(data.url);
						var path = fileCtx + data.url;
						$("#licensePicImg").attr("src",path);
					}
				}
			});
		}
	};

}();